//
//  ViewController.m
//  FQChargingProgressView
//
//  Created by issuser on 2021/11/10.
//

#import "ViewController.h"
#import "FQScoreProgressView.h"
#import "FQChargingProgressView.h"
#import "FQGradientProgressView.h"
#import "FQGradientCircleView.h"

@interface ViewController ()
@property (nonatomic, strong) FQScoreProgressView* progressView;//进度视图1
@property (nonatomic, strong) FQChargingProgressView * progressView1;//进度图2
@property (nonatomic, strong) FQGradientProgressView * gradientView;//风火轮优化
@property (nonatomic ,strong) FQGradientCircleView *gradientCircleView;
@property (weak, nonatomic) IBOutlet UIButton *chargingBtn1;
@property (weak, nonatomic) IBOutlet UIButton *chargingBtn2;
@property (weak, nonatomic) IBOutlet UIButton *otherBtn3;
@property (weak, nonatomic) IBOutlet UIButton *otherBtn4;
@property (weak, nonatomic) IBOutlet UISlider *sliderView;
@property (weak, nonatomic) IBOutlet UIButton *changeBtn;
@property (strong, nonatomic) UIButton *selectBtn;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.selectBtn = self.chargingBtn1;
    [self.view addSubview:self.progressView];
    [self.view addSubview:self.progressView1];
    [self.progressView1 reloadProgressWithValue:0];
    self.progressView1.hidden = YES;
    [self.view addSubview:self.gradientView];
    self.gradientView.hidden = YES;
    self.changeBtn.hidden = YES;
}

- (IBAction)changeSlider:(UISlider *)sender {
    if ([self.selectBtn isEqual:self.chargingBtn1]) {
        self.progressView.progress = MAX(sender.value, 0);
    }else if([self.selectBtn isEqual:self.chargingBtn2]){
        [self.progressView1 reloadProgressWithValue:sender.value * 36.0];
    }
}
- (IBAction)clickCharginBtn1:(UIButton *)sender {
    self.selectBtn = sender;
    self.progressView.hidden = NO;
    self.progressView1.hidden = YES;
    self.gradientView.hidden = YES;
    self.sliderView.hidden = NO;
    self.changeBtn.hidden = YES;
    self.gradientCircleView.hidden = YES;
    self.progressView.progress = MAX(self.sliderView.value, 0);
}
- (IBAction)clickChargingBtn2:(UIButton *)sender {
    self.selectBtn = sender;
    self.progressView.hidden = YES;
    self.progressView1.hidden = NO;
    self.gradientView.hidden = YES;
    self.sliderView.hidden = NO;
    self.changeBtn.hidden = YES;
    self.gradientCircleView.hidden = YES;
    [self.progressView1 reloadProgressWithValue:self.sliderView.value * 36.0];
}

- (IBAction)clickChargingBtn3:(UIButton *)sender {
    self.selectBtn = sender;
    self.progressView.hidden = YES;
    self.progressView1.hidden = YES;
    self.gradientView.hidden = NO;
    self.sliderView.hidden = YES;
    self.changeBtn.hidden = NO;
    self.gradientCircleView.hidden = YES;
    [self changeGradientBtn:nil];
}

- (IBAction)clickChargingBtn4:(UIButton *)sender {
    self.selectBtn = sender;
    self.progressView.hidden = YES;
    self.progressView1.hidden = YES;
    self.gradientView.hidden = YES;
    self.sliderView.hidden = YES;
    self.changeBtn.hidden = NO;
    self.gradientCircleView.hidden = NO;
    [self changeGradientBtn:nil];
}

- (IBAction)changeGradientBtn:(UIButton *)sender {
    NSMutableArray * muArr = [NSMutableArray array];
    for (int i = 0; i < 4; i++) {
        int arc = arc4random_uniform(10);
        [muArr addObject:@(arc * 10)];
    }
    FQGradientProgressConfig * config = [[FQGradientProgressConfig alloc]init];
    config.angleValues = muArr.copy;
    self.gradientView.config = config;
    self.gradientCircleView.config = config;
}

-(FQScoreProgressView *)progressView
{
    if (!_progressView) {
        
        CGFloat layerW = 250 * self.view.bounds.size.width / 360;
        CGFloat layerH = 237 * layerW / 250.0;
        _progressView = [[FQScoreProgressView alloc]initWithFrame:CGRectMake((self.view.bounds.size.width - layerW) * 0.5, 100, layerW, layerH)];
        _progressView.backgroundColor = [UIColor clearColor];
        _progressView.userInteractionEnabled = NO;
//        [self.view addSubview:_progressView];
    }
    return _progressView;
}

-(FQChargingProgressView *)progressView1
{
    if (!_progressView1) {
        CGFloat layerW = 350.0;
        _progressView1 = [[FQChargingProgressView alloc]initWithFrame:CGRectMake(0, 0, layerW, layerW)];
        _progressView1.center = CGPointMake(self.view.bounds.size.width * 0.5, 350 * 0.5 + 100);
        _progressView1.backgroundColor = UIColor.blackColor;
//        [self.view addSubview:_progressView1];
        //布局建议用约束
//        [self.progressView1 mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.equalTo(self.topContentView.mas_centerX);
//            make.centerY.equalTo(self.topContentView.mas_centerY);
//            make.width.height.mas_equalTo(350);
//        }];
    }
    return _progressView1;
}

-(FQGradientProgressView *)gradientView
{
    if (!_gradientView) {
        CGFloat layerW = 84 * 2.0 + 24;
        _gradientView = [[FQGradientProgressView alloc]initWithFrame:CGRectMake((self.view.bounds.size.width - layerW) * 0.5, 100, layerW, layerW)];
    }
    return _gradientView;
}

-(FQGradientCircleView *)gradientCircleView
{
    if (!_gradientCircleView) {
        FQGradientProgressConfig * config = [[FQGradientProgressConfig alloc]init];
        //设置四段圆环的值
        config.angleValues = @[@100,@100,@100,@100];
        //设置四段圆环的颜色
    //    config.gradients = gradientColors;
        //设置半径
        config.radius = 84;
        //设置线宽
        config.rWidth = 24;
        //获取绘制的layerWH
        CGFloat layerW = config.radius * 2.0 + config.rWidth; //84 * 2.0 + 24
        _gradientCircleView = [[FQGradientCircleView alloc]initWithFrame:CGRectMake((self.view.bounds.size.width - layerW) * 0.5, 100, layerW, layerW) config:config];
        _gradientCircleView.backgroundColor = UIColor.blackColor;
        [self.view addSubview:_gradientCircleView];
    }
    return _gradientCircleView;
}

@end
